package com.wx.registerclient.proxy;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.Proxy;
@Component
public class RemoteInvokeFactory<T> implements FactoryBean<T> {

    @Autowired
    private RemoteInvokeHandler remoteInvokeHandler;
    private Class<T> interfaceType;

  public RemoteInvokeFactory(){}
  public RemoteInvokeFactory(Class<T> interfaceType){
      this.interfaceType=interfaceType;
  }





    @Override
    public T getObject() throws Exception {


        //创建代理类加强逻辑对象
       /* RemoteInvokeHandler remoteInvokeHandler = new RemoteInvokeHandler(interfaceType);*/
        T o =(T) Proxy.newProxyInstance(interfaceType.getClassLoader(), new Class[]{interfaceType}, remoteInvokeHandler);

        return o;

    }

    @Override
    public Class<?> getObjectType() {
        return interfaceType;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
